package com.ebspp.server;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.thrift.TException;

import com.ebspp.server.resource.ClientResManager;
import com.ebspp.server.resource.ResourceManager;
import com.ebspp.thrift.DataMsg;
import com.ebspp.thrift.Identity;
import com.ebspp.thrift.MsgTransfer;
import com.ebspp.thrift.ResourceType;
import com.ebspp.thrift.DataRead.Processor;

/**
 * A RPC handler for the remote client message calls
 * It serves resource information retrieval and resource provisioning
 * @author x23pan
 *
 */
public class MsgHandler implements MsgTransfer.Iface
{

	//resource information retrieval
	@Override
	public Map<ResourceType, Integer> quest() throws TException 
	{
		// TODO Auto-generated method stub
		Map<ResourceType, Integer> resourceMap = new HashMap<ResourceType, Integer>();
		for(ResourceType type : ResourceType.values())
			resourceMap.put(type, ResourceManager.getResource(type));

		return resourceMap;
	}

	@Override
	public boolean deWatch(ResourceType type, Identity wID, String IP)
			throws TException {
		// TODO Auto-generated method stub
		ClientResManager resManager = ResourceManager.getResManager(wID);
		if(resManager == null)
			return false;
		
		return resManager.deWatch(type, IP);
	}


	@Override
	public boolean watch(ResourceType type, Identity wID, String IP)
			throws TException {
		// TODO Auto-generated method stub
		ClientResManager resManager = ResourceManager.getResManager(wID);
		if(resManager == null)
			return false;
		
		return resManager.watch(type, IP);
	}

}
